#![allow(unused)]
struct Tweet<'a> {
    content: &'a str,
}

impl<'a> Tweet<'a> {
    fn replace_content(&mut self, content: &'a str) -> &str {
        let old_content = self.content;
        self.content = content;
        old_content
    }
}

trait UIComponent {
    fn render(&self) {
        print!("render")
    }
}

struct Button {
    text: String,
}

impl UIComponent for Button {}
struct Container {
    name: String,
    child: Box<Container>,
}

fn main() {
    let button = Button {
        text: String::from("hello"),
    };
    let button_b = Box::new(Button {
        text: "button b".to_string(),
    });
    let button_c = button;
    let button_d = button_b;

    let components: Vec<Box<dyn UIComponent>> = vec![Box::new(button_c), button_d];
    // let r1;
    // {
    //     let s1 = String::from("hello");
    //     r1 = &s1;
    //     println!("r1:{}", r1);
    // }
    // let mut s1 = String::from("hello");
    // let r1 = &s1;
    // println!("r1:{r1}");
    // let r2 = &mut s1;
    // r2.push_str(" world");
    // println!("r2:{r2}");

    // let player1 = String::from("player1");
    // let player2 = String::from("player2");
    // let result = first_turn(player1.as_str(), player2.as_str());
    // println!("result:{result}");

    let player1 = String::from("player1");
    let result;
    {
        let player2 = String::from("player2");
        result = second_turn(player1.as_str(), player2.as_str());
    }
    println!("result:{result}");

    let mut tweet = Tweet {
        content: "hello world",
    };
    let old_content = tweet.replace_content("hello rust");
    println!("old_content:{old_content}");
}

fn first_turn<'a>(player1: &'a str, player2: &'a str) -> &'a str {
    if player1 == "player1" {
        player1
    } else {
        player2
    }
}

fn second_turn<'a>(player1: &'a str, player2: &str) -> &'a str {
    let s: &'static str = "hello";
    s
}
